package one.stand.service.impl;

import one.stand.model.CompanyAccountModel;
import one.stand.model.ResultModel;
import one.stand.request.CompanyAccountRequest;
import one.stand.response.CompanyAccountResponse;
import one.stand.service.CompanyAccountService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: QIK
 * @CreateDate: 2019/5/13 17:18
 */
@Service
@Transactional
public class CompanyAccountServiceImpl extends PublicBaseService implements CompanyAccountService {


    @Override
    public ResultModel<List<CompanyAccountResponse>> getAccountList(CompanyAccountRequest request) {
        List<CompanyAccountModel> list=companyAccountMapper.selectList(new CompanyAccountModel(){{
            setCompanyId(request.getCId().intValue());
        }});
        List<CompanyAccountResponse> responseList=new ArrayList<>();
        list.forEach(l->{
            CompanyAccountResponse response=new CompanyAccountResponse();
            BeanUtils.copyProperties(l,response);
            if(!StringUtils.isEmpty(response.getAppSecret())){
                response.setAppSecret("**************************");
            }
            responseList.add(response);
        });
        return ResultModel.success(responseList);
    }
}
